function $(id){
	return document.getElementById(id);
}
/**
*删除左右两端的空格
*/
String.prototype.trim=function(){   
  	return this.replace(/(^\s*)|(\s*$)/g, '');
}  
/**
*删除左边的空格
*/
String.prototype.ltrim=function()
{
  return this.replace(/(^s*)/g,'');
}
/**
*删除右边的空格
*/
String.prototype.rtrim=function()
{
  return this.replace(/(s*$)/g,'');
}


//检查是否只有数字组成，且长度为10
function isDigit(s) 
{ 
	var patrn=/^[0-9]{10,10}$/; 
	if (!patrn.exec(s)) 
		return false; 
	return true; 
}
//校验密码：只能输入6-20个字母、数字、下划线
function isPasswd(s)   
{   
	var patrn=/^(\w){5,20}$/;   
	if (!patrn.exec(s)) 
		return false;  
	return true;  
}
//校验账号，只能以字母开头
function isUser(s){
	var patrn=/^[a-zA-Z0-9_]{3,20}$/;
	if (!patrn.exec(s)) 
		return false;  
	return true; 
}
//校验是否为标准的email地址
function isEmail(s){
	var patrn=/\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/;
	if (!patrn.exec(s)) 
		return false;  
	return true; 

}
   
//校验账号：只能输入6-20个字母、数字、下划线
function checkUserID(){
	var nikeName = document.getElementById("userID").value;
	if(nikeName.trim()==""||nikeName==null){//如果账号为空
		str = "<img src='images/register2.png'>&nbsp;账号不能为空";
		document.getElementById("userID.info").innerHTML=str;
	}else{
		if(!isUser(nikeName)){
			str = "<img src='images/register2.png'>&nbsp;账号格式不正确";
			document.getElementById("userID.info").innerHTML=str;
		}else{
			str = "<img src='images/register1.png'>";
			document.getElementById("userID.info").innerHTML=str;
			return true;
		}
	}
	return false;
}
//检测密码是否符合规范
function checkPassword(){
	var p1 = document.getElementById("password").value;
	if(p1.trim()==""||p1==null){
		str = "<img src='images/register2.png'>&nbsp;密码不能为空";
		document.getElementById("password.info").innerHTML=str;
	}else if(!isPasswd(p1)){
		str = "<img src='images/register2.png'>&nbsp;包含非法字符或长度错误";
		document.getElementById("password.info").innerHTML=str;
	}else{
		str = "<img src='images/register1.png'>";
		document.getElementById("password.info").innerHTML=str;
		return true;
	}
	return false;
}

//检查两次密码输入是否一致，且不能为空
function checkRptPassword(){
	var p1 = document.getElementById("password").value;
	var p2 = document.getElementById("rptPassword").value;
	
    if(p1 != p2)
	{
		str = "<img src='images/register2.png'>&nbsp;密码不一致";
		document.getElementById("rptPassword.info").innerHTML=str;
	}else {
		str = "<img src='images/register1.png'>";
		document.getElementById("rptPassword.info").innerHTML=str;
		return true;
	}
	return false;
}
//检查email是否符合规范
function checkEmail(){
	var email = document.getElementById("email").value;
	
	if(email.trim()==""||email==null){
		str = "<img src='images/register2.png'>&nbsp;邮箱不能为空";
		document.getElementById("email.info").innerHTML=str;
	}else if(!isEmail(email)){
		str = "<img src='images/register2.png'>&nbsp;请填写正确的Email地址";
		document.getElementById("email.info").innerHTML=str;
	}else{
		str = "<img src='images/register1.png'>";
		document.getElementById("email.info").innerHTML=str;
		return true;
	}
	return false;
}
//检查班级信息是否是“计科0701”的格式
function isClazz(s) {
	var patrn = /^[\u4E00-\u9FA5]{2}[0-9]{4}$/;   
	if (!patrn.exec(s)) 
		return false;  
	return true; 
}
//检查班级信息
function checkClazz(){
	var clazz = document.getElementById("clazz").value;
	if(clazz.trim()==""||clazz==null){
		str = "<img src='images/register2.png'>&nbsp;班级不能为空";
		document.getElementById("clazz.info").innerHTML=str;
	}else if(!isClazz(clazz)){
		str = "<img src='images/register2.png'>&nbsp;请按照正确的格式填写班级";
		document.getElementById("clazz.info").innerHTML=str;
	}else{
		str = "<img src='images/register1.png'>";
		document.getElementById("clazz.info").innerHTML=str;
		return true;
	}
	return false;
}

//检查学号信息
function checkSno() {
	var sno = document.getElementById("sno").value;
	if(sno.trim()==""||sno==null){
		str = "<img src='images/register2.png'>&nbsp;学号不能为空";
		document.getElementById("sno.info").innerHTML=str;
	}else if(!isDigit(sno)){
		str = "<img src='images/register2.png'>&nbsp;格式不正确";
		document.getElementById("sno.info").innerHTML=str;
	}else{
		str = "<img src='images/register1.png'>";
		document.getElementById("sno.info").innerHTML=str;
		return true;
	}
	return false;
}

//检查姓名的格式（2-6个汉字）
function isRealName(s) {
	var patrn = /^[\u4E00-\u9FA5]{2,6}$/;   
	if (!patrn.exec(s)) 
		return false;  
	return true; 
}

//检查真实姓名
function checkRealName(){
	var realname = document.getElementById("realname").value;
	if(realname.trim()==""||realname==null){
		str = "<img src='images/register2.png'>&nbsp;姓名不能为空";
		document.getElementById("realname.info").innerHTML=str;
	}else if(!isRealName(realname)){
		str = "<img src='images/register2.png'>&nbsp;格式不正确";
		document.getElementById("realname.info").innerHTML=str;
	}else{
		str = "<img src='images/register1.png'>";
		document.getElementById("realname.info").innerHTML=str;
		return true;
	}
	return false;
}
//检查是否符合手机号码的规范
function isPhoneNumber(s) {
	var patrn=/^[0-9]{7,11}$/;   
	if (!patrn.exec(s)) 
		return false;  
	return true; 
}


//检查联系方式是否正确电话号码是有11位数字组成
function checkPhone() {
	var phone = document.getElementById("phone").value;
	if(phone.trim()==""||phone==null){
		str = "<img src='images/register2.png'>&nbsp;姓名不能为空";
		document.getElementById("phone.info").innerHTML=str;
	}else if(!isPhoneNumber(phone)){
		str = "<img src='images/register2.png'>&nbsp;格式不正确";
		document.getElementById("phone.info").innerHTML=str;
	}else{
		str = "<img src='images/register1.png'>";
		document.getElementById("phone.info").innerHTML=str;
		return true;
	}
	return false;
}


//最后检查表单是否合格
function testForm(){
	if(!checkUserID()||!checkPassword()||!checkRptPassword()||!checkClazz()||!checkSno()||!checkRealName()||!checkPhone()||!checkEmail()){
		return false;
	}
	return true;
}

function checkNewPwd() {
	var newPassword = document.getElementById("newpassword").value;
	var rpt2Password = document.getElementById("rptPassword").value;
	if((newPassword==null||newPassword=="")&&(rpt2Password==null||rpt2=="")){
		return true;
	}else{
		if(newPassword!=rpt2Password){
			str = "<img src='images/register2.png'>&nbsp;两次输入的密码不一致";
			document.getElementById("rptPassword.info").innerHTML=str;
		}else {
			str = "<img src='images/register1.png'>";
			document.getElementById("rptPassword.info").innerHTML=str;
			return true;
		}
	}return false;
}

function userEditCheck() {
	if(!checkClazz()||!checkSno()||!checkRealName()||!checkPhone()||!checkEmail()||!checkPassword()){
		return false;
	}
	return true;
}

function set(){
	document.getElementById("userID.info").innerHTML="*";
	document.getElementById("password.info").innerHTML="*";
	document.getElementById("rptPassword.info").innerHTML="*";
	document.getElementById("email.info").innerHTML="*";
	document.getElementById("sno.info").innerHTML="*";
	document.getElementById("phone.info").innerHTML="*";
	document.getElementById("clazz.info").innerHTML="*";
	document.getElementById("realname.info").innerHTML="*";
}

//返回上一页
function turnBack(){
	history.back();
}